package com.oneday.nuo.base.controller;


import cn.hutool.core.lang.tree.Tree;
import com.oneday.nuo.base.dto.NuoMenuDTO;
import com.oneday.nuo.base.entity.NuoMenuEntity;
import com.oneday.nuo.base.response.NuoResult;
import com.oneday.nuo.base.service.NuoMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (NuoMenu)表控制层
 *
 * @author liushuai
 * @since 2021-03-13 23:37:19
 */
@RestController
@RequestMapping("api/menu")
@Api(tags="NuoMenuController")
@ApiModel(value = "",description = "菜单表")
public class NuoMenuController {
    @Autowired
    private NuoMenuService nuoMenuService;

    @ApiOperation(value = "保存菜单" ,  notes="保存菜单")
    @PostMapping("saveMenu")
    public NuoResult saveMenu(@RequestBody NuoMenuDTO nuoMenuDTO){
        nuoMenuService.saveMenu(nuoMenuDTO);
        return NuoResult.buildResponseSave();
    }
    @ApiOperation(value = "查询所有菜单" ,  notes="查询所有菜单")
    @PostMapping("queryMenuAll")
    public NuoResult queryMenuAll(){
        List<Tree<String>> entityList = nuoMenuService.queryMenuAll();
        return NuoResult.buildResponseQuery(entityList);
    }
    @ApiOperation(value = "查询所有菜单" ,  notes="查询所有菜单")
    @GetMapping("queryRoute")
    public NuoResult queryRoute(){
        List<NuoMenuEntity> entityList = nuoMenuService.queryRoute();
        return NuoResult.buildResponseQuery(entityList);
    }


    @ApiOperation(value = "根据id获取菜单列表" ,  notes="根据id获取菜单列表")
    @GetMapping("queryMenuById")
    public NuoResult queryMenuById(@RequestParam("id") String id){
        NuoMenuDTO entity =  nuoMenuService.queryMenuById(id);
        return NuoResult.buildResponseQuery(entity);
    }
    @ApiOperation(value = "删除菜单以及子菜单" ,  notes="删除菜单以及子菜单")
    @GetMapping("deleteMenuById")
    public NuoResult deleteMenuById(@RequestParam("id") String id){
        nuoMenuService.deleteMenuById(id);
        return NuoResult.buildResponseDelete();
    }







}